package com.fh.controller;

import com.auth0.jwt.impl.JWTParser;
import com.fh.model.ShoppingCart;
import com.fh.service.ShoppingCartService;
import com.fh.utils.Base64Utils;
import com.fh.utils.ResultState;
import com.fh.vo.ResultVo;
import io.jsonwebtoken.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("shopcart")
@Api(value = "",tags = "购物车管理")
@CrossOrigin
public class ShopcartController {

    @Resource
   private ShoppingCartService shoppingCartService;

    @ApiImplicitParam(dataType = "string",name = "userId", value = "用户Id",required =
            true)
    @GetMapping("list")
  public ResultVo list(Integer userId){

        return  shoppingCartService.selectShoppingCart(userId);
    }


    @PostMapping("add")
    public ResultVo addCart(@RequestBody ShoppingCart cart ){



        return  shoppingCartService.addCart(cart);
    }

    @GetMapping("listByCid")
    public ResultVo selectCartByCartId(String cartIds){
        return  shoppingCartService.selectCartByCartId(cartIds);
    }

    @PutMapping("update/{cartId}/{cartNum}")
  public  ResultVo updateNum(@PathVariable("cartId") Integer cartId,@PathVariable("cartNum") String cartNum){
        return  shoppingCartService.updateNum(cartId,cartNum);

    }




}
